<?
include("common/header.html");
include("common/left.html");
//include("common/billcommon.php");
$memberID=$_SESSION['sid'];
$smethodT=array(0=>"月结",1=>"半月结",2=>"日结");
$settles=array();
$r=array();
$sql = "select fid, aid, stype, `status`, billdate, smethod, begintime, id from uu_settle where `%ID%`=$memberID and status=0";
if($_REQUEST['about']=="get"){
	$replace = 'aid';
}else{
    $replace = 'fid';
}
$sql = str_replace('%ID%', $replace, $sql);
//echo $sql;
$GLOBALS['le']->query($sql);
while($row=$GLOBALS['le']->fetch_assoc()){
	$r[]=$row;
}
//print_r($r);
$dnames = include '/var/www/html/new/d/module/link_product/Member.cache.php';
//$str="select id,dname from pft_member";
//$GLOBALS['le']->query($str);
//while($row=$GLOBALS['le']->fetch_assoc()){
//	$dnames[$row['id']]=$row['dname'];
//}
?>
<link rel="stylesheet" href="css/getbill.css"/>
<div class="clay">
	<h3 class="mc_title">
		<span class="mctit_1"><span class="mctit_2">应收款账单</span></span>
	</h3>
	<ul class="navi">
		<li><a href="getbill.html">已出账单</a></li>
		<li><a href="#" class="settle current">结算周期配置</a></li>
	</ul>

	<table>
		<tr>
			<?if($_REQUEST['about']=="get"){?>
			<th class="col1">分销商</th>
			<?}else{?>
			<th class="col1">供应商</th>
			<?}?>
			<th>结算周期</th>
			<th>账单日</th>
			<?if($_REQUEST['about']=="get"){?>
			<th>操作</th>
			<?}?>
		</tr>
		<?foreach($r as $row){?>
		<tr>
			<?if($_REQUEST['about']=="get"){?>
			<td title="<?=$row['fid']?>" class="col1"><?=$dnames[$row['fid']]?></td>
			<?}else{?>
			<td title="<?=$row['aid']?>" class="col1"><?=$dnames[$row['aid']]?></td>
			<?}?>
			<td><span class="smethod"><?=$smethodT[$row['smethod']]?></span></td>
			<td><span class="billdate"><?=$row['billdate'].$billdateT[$row['smethod']]?></span></td>
			<?if($_REQUEST['about']=="get"){?>
			<td><a href="#" settleid="<?=$row['id']?>" smethod="<?=$row['smethod']?>" billdate="<?=$row['billdate']?>" class="edite">修改</a></td>
			<?}?>
		</tr>	
		<?}?>
	</table>
</div>
<div class="config_div" id="config_div">
	<div class="tp"></div>
	<form action="handle.php" target="sub" class="config">
		<input type="hidden" id="settleid" name="settleid"/>
		<input type="hidden" name="from" value="settle_config"/>
	<!-- 	<span>
			<label>结算周期：</label>
			<select name="smethod">
				<option value="1">月结</option>
				<option value="2">半月结</option>
				<option value="0">日结</option>
			</select>
		</span> -->
		<span>
			<label>账单日：</label>
			<select name="billdate" class="billdate">
				<option>0</option>
				<option>1</option>
				<option>2</option>
				<option>3</option>
				<option>4</option>
				<option>5</option>
				<option>6</option>
				<option>7</option>
				<option>8</option>
				<option>9</option>
				<option>10</option>
				<option>11</option>
				<option>12</option>
				<option>13</option>
				<option>14</option>
				<option>15</option>
				<option>16</option>
				<option>17</option>
				<option>18</option>
				<option>19</option>
				<option>20</option>
				<option>21</option>
				<option>22</option>
				<option>23</option>
				<option>24</option>
				<option>25</option>
				<option>26</option>
				<option>28</option>
				<option>28</option>
				<option>29</option>
				<option>30</option>
				<option>31</option>
			</select>
			<label>日</label>
		</span>
		<input type="submit"  class="confirm" value="确定"/>
	</form>
</div>
<script type="text/javascript" src="js/ui/PopWindow.js"></script>
<script>
	$("form.config").submit(function(){
		var str=$(this).serialize();
		$.ajax({
			"url":"call/handle.php?"+str,
			"dataType":"json",
			"success":function(data){
				if(data.outcome==1){
					alert("配置成功");
					window.location=window.location.href;
				}
				$("#config_div").css({"display":"none"});
			}
		});
		return false;
	});
	/*结算配置*/
	(function(){
		var dayT={0:"日",1:"日",2:"点"};
		$(".edite").click(function(){
			$("#config_div").css({"display":"block","left":$(this).offset().left-324,"top":$(this).offset().top+20})
			$("#stype").val($(this).attr("stype"));
			$("#settleid").val($(this).attr("settleid"));
			var smethod=$(this).attr("smethod");
			var billdate=$(this).attr("billdate");
			$("#config_div select[name='smethod'] option").each(function(){
				if(this.value==smethod){
					this.selected=true;
				}
			});
			$("#config_div select[name='billdate'] option").each(function(){
				if(this.value==billdate){
					this.selected=true;
				}
				if(smethod==2&&this.value>23){
					$(this).css({"display":"none"});
				}else{
					$(this).css({"display":""});
				}
			})
			$("#config_div select[name='billdate']").next().first().html(dayT[smethod]);
			return false;
		});
		$("#config_div select[name='smethod']").change(function(){
			var smethod=this.value;
			$("#config_div select[name='billdate'] option").each(function(){
				if(smethod==2){
					if(this.value==2){
						this.selected=true;
					}
					if(this.value>24){
						$(this).css({"display":"none"});
					}
				}else if(smethod==0){
					if(this.value==31){
						this.selected=true;
					}
					$(this).css({"display":""});
				}else if(smethod==1){
					if(this.value==15){
						this.selected=true;
					}
					$(this).css({"display":""});
				}
			});
			$("#config_div select[name='billdate']").next().first().html(dayT[smethod]);
		});
		
		$("#config_div .confirm").click(function(){
			$("#config_div").css({"display":"none"});
		});
	})();
	$(".resettle").click(function(){
		if(!confirm("确定要删除结算未完成的账单，并重新生成账单？")){
			return false;
		}
	});
</script>
<?include("common/footer.html");?>